home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 7: Programming / CDAT7.iso / demos / VisualAge for Java 2.0 Entry / setup / data1.cab / ide-e / IDE / cache / 1OF2AVT (.txt) < prev    next >
Encoding:
Java Class File  |  1998-09-16  |  2.1 KB  |  76 lines

  1. package com.sun.java.swing.border;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Graphics;
  6. import java.awt.Insets;
  7.  
  8. public class LineBorder extends AbstractBorder {
  9.    private static Border blackLine;
  10.    private static Border grayLine;
  11.    protected int thickness;
  12.    protected Color lineColor;
  13.    protected boolean roundedCorners;
  14.  
  15.    public LineBorder(Color color) {
  16.       this(color, 1, false);
  17.    }
  18.  
  19.    public LineBorder(Color color, int thickness) {
  20.       this(color, thickness, false);
  21.    }
  22.  
  23.    LineBorder(Color color, int thickness, boolean roundedCorners) {
  24.       this.lineColor = color;
  25.       this.thickness = thickness;
  26.       this.roundedCorners = roundedCorners;
  27.    }
  28.  
  29.    public static Border createBlackLineBorder() {
  30.       if (blackLine == null) {
  31.          blackLine = new LineBorder(Color.black, 1);
  32.       }
  33.  
  34.       return blackLine;
  35.    }
  36.  
  37.    public static Border createGrayLineBorder() {
  38.       if (grayLine == null) {
  39.          grayLine = new LineBorder(Color.gray, 1);
  40.       }
  41.  
  42.       return grayLine;
  43.    }
  44.  
  45.    public Insets getBorderInsets(Component c) {
  46.       return new Insets(this.thickness, this.thickness, this.thickness, this.thickness);
  47.    }
  48.  
  49.    public Color getLineColor() {
  50.       return this.lineColor;
  51.    }
  52.  
  53.    public int getThickness() {
  54.       return this.thickness;
  55.    }
  56.  
  57.    public boolean isBorderOpaque() {
  58.       return true;
  59.    }
  60.  
  61.    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
  62.       Color oldColor = g.getColor();
  63.       g.setColor(this.lineColor);
  64.  
  65.       for(int i = 0; i < this.thickness; ++i) {
  66.          if (!this.roundedCorners) {
  67.             g.drawRect(x + i, y + i, width - i - i - 1, height - i - i - 1);
  68.          } else {
  69.             g.drawRoundRect(x + i, y + i, width - i - i - 1, height - i - i - 1, this.thickness, this.thickness);
  70.          }
  71.       }
  72.  
  73.       g.setColor(oldColor);
  74.    }
  75. }
  76.